package cn.liutao.common.entity;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;
import com.mybatisflex.core.paginate.Page;
import lombok.Data;

import java.util.List;

/**
 * @author liutao
 * @Description 封装了统一的接口返回格式
 * @date 2023/10/30 19:53
 * @Version 1.0
 */
@Data
public class ResultMap<T> {

    private T data;
    private String msg;
    private Integer status;
    private Integer pageNum;
    private Integer pageSize;
    private Integer totalRow;
    private List<T> rows;

    public ResultMap(T data, String msg, Integer status) {
        this.data = data;
        this.msg = msg;
        this.status = status;
    }

    public ResultMap(Page<T> tPage, String msg, Integer status) {
        if (ObjectUtil.isNotNull(tPage)){
            this.rows =tPage.getRecords();
            this.pageNum = (int)tPage.getPageNumber();
            this.pageSize = (int) tPage.getPageSize();
            this.totalRow = (int) tPage.getTotalRow();
        }
        this.msg = msg;
        this.status = status;

    }


    public ResultMap(String msg, Integer status) {
        this.msg = msg;
        this.status = status;
    }



}
